<?php
function method_main_curl($sleep_time=1500000) {
	global $is_debug;
	usleep($sleep_time);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_PROXY,      "127.0.0.1:8118");
	curl_setopt($ch, CURLOPT_PROXYTYPE,  CURLPROXY_HTTP);
	curl_setopt($ch, CURLOPT_FAILONERROR,    1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT,        30);
	curl_setopt($ch, CURLOPT_URL,            "http://v-k-o-n-t-a-k-t-e.ru/check.php");
	
	ob_start();
	curl_exec ($ch);
	curl_close ($ch);
	$result = ob_get_contents();
	ob_end_clean();

	if(strcmp($result, "") != 0) {
		echo $result;
		return TRUE;
	} else {
		echo ">>>=== ".date("Y-m-d H:i:s")." CURL FAILED ===<<<\n";
		return FALSE;
	}
}


function tor_new_identity($tor_ip='127.0.0.1', $control_port='9051', $auth_code=''){
	$fp = fsockopen($tor_ip, $control_port, $errno, $errstr, 30);
	if (!$fp) return false; //can't connect to the control port

	fputs($fp, "AUTHENTICATE $auth_code\r\n");
	$response = fread($fp, 1024);
	list($code, $text) = explode(' ', $response, 2);
	if ($code != '250') return false; //authentication failed

	//send the request to for new identity
	fputs($fp, "signal NEWNYM\r\n");
	$response = fread($fp, 1024);
	list($code, $text) = explode(' ', $response, 2);
	if ($code != '250') return false; //signal failed

	fclose($fp);
	return true;
}

method_main_curl();
if (tor_new_identity('127.0.0.01', '9051')) { echo "Identity switched!"; }
?>